﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Threading;
using System.ComponentModel;

namespace ClockMagnet
{
    internal class ClockEngine : INotifyPropertyChanged
    {
        public int TotalMinutes
        {
            get { return Convert.ToInt32(DateTime.Now.TimeOfDay.TotalMinutes); }
        }

        public int Second
        {
            get { return DateTime.Now.Second; }
        }

        DispatcherTimer _timer;

        public ClockEngine()
        {
            _timer = new DispatcherTimer();
            _timer.Interval = new TimeSpan(0, 0, 1);
            _timer.Tick += new EventHandler(timer_Tick);
            _timer.Start();
        }

        public void Stop()
        {
            _timer.Stop();
        }

        void timer_Tick(object sender, EventArgs e)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("TotalMinutes"));
                PropertyChanged(this,new PropertyChangedEventArgs("Second"));
            }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }
}
